package com.summary.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.summary.domain.WeekTime;
import com.summary.service.IWeekTimeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 每周时间Controller
 *
 * @author ruoyi
 * @date 2024-01-15
 */
@RestController
@RequestMapping("/time")
public class WeekTimeController extends BaseController
{
    @Autowired
    private IWeekTimeService weekTimeService;

    /**
     * 查询每周时间列表
     */

    @GetMapping("/list")
    public TableDataInfo list(WeekTime weekTime)
    {
        startPage();
        List<WeekTime> list = weekTimeService.selectWeekTimeList(weekTime);
        return getDataTable(list);
    }

    /**
     * 导出每周时间列表
     */
    @PreAuthorize("@ss.hasPermi('system:time:export')")
    @Log(title = "每周时间", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WeekTime weekTime)
    {
        List<WeekTime> list = weekTimeService.selectWeekTimeList(weekTime);
        ExcelUtil<WeekTime> util = new ExcelUtil<WeekTime>(WeekTime.class);
        util.exportExcel(response, list, "每周时间数据");
    }

    /**
     * 获取每周时间详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:time:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(weekTimeService.selectWeekTimeById(id));
    }

    /**
     * 新增每周时间
     */
    @PreAuthorize("@ss.hasPermi('system:time:add')")
    @Log(title = "每周时间", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WeekTime weekTime)
    {
        return toAjax(weekTimeService.insertWeekTime(weekTime));
    }

    /**
     * 修改每周时间
     */
    @PreAuthorize("@ss.hasPermi('system:time:edit')")
    @Log(title = "每周时间", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WeekTime weekTime)
    {
        return toAjax(weekTimeService.updateWeekTime(weekTime));
    }

    /**
     * 删除每周时间
     */
    @PreAuthorize("@ss.hasPermi('system:time:remove')")
    @Log(title = "每周时间", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(weekTimeService.deleteWeekTimeByIds(ids));
    }
}
